package com.muyu.day3zy.service.impl;

import com.muyu.day3zy.domain.BrandInfo;
import com.muyu.day3zy.domain.ProductInfo;
import com.muyu.day3zy.domain.PromotionInfo;
import com.muyu.day3zy.domain.SkuInfo;
import com.muyu.day3zy.domain.vo.PromotionInfoVo;
import com.muyu.day3zy.mapper.GoodsMapper;
import com.muyu.day3zy.service.GoodsService;
import com.muyu.day3zy.unit.ProductConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName GoodsServiceImpl
 * @Description 描述
 * @Author ShiYu.Cui
 * @Date 2024/3/24 11:24
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Override
    public List<BrandInfo> list() {
        return goodsMapper.list();
    }

    @Override
    public void addProductInfo(ProductInfo productInfo) {
        goodsMapper.addProductInfo(productInfo);
        redisTemplate.opsForValue().set(ProductConstants.PRODUCT_ID,String.valueOf(productInfo.getId()));
    }

    @Override
    public void addPromotionInfo(PromotionInfoVo promotionInfoVo) {
        Integer productId = Integer.valueOf(redisTemplate.opsForValue().get(ProductConstants.PRODUCT_ID));
        promotionInfoVo.setProductId(productId);
        goodsMapper.addPromotionInfo(promotionInfoVo);
        if(promotionInfoVo.getDiscountsId()==2){
            goodsMapper.addPreferenceInfo(promotionInfoVo);
        }
        if(promotionInfoVo.getDiscountsId()==3){
            goodsMapper.addMemberInfo(promotionInfoVo);
        }
        if(promotionInfoVo.getDiscountsId()==4){
            goodsMapper.addLadderInfo(promotionInfoVo);
        }
        if(promotionInfoVo.getDiscountsId()==5){
            goodsMapper.addMaxOutInfo(promotionInfoVo);
        }
    }

    @Override
    public void addSkuInfo(SkuInfo skuInfo) {

    }

}
